package com.zyh.system.supermark1.dao.impl;

import com.zyh.system.supermark1.dao.BuyCarDao;
import com.zyh.system.supermark1.domain.BuyCar;
import com.zyh.system.supermark1.domain.User;

import java.util.LinkedList;

public class BuyCarDaoImpl implements BuyCarDao {
    public static final LinkedList<BuyCar> CAR_LIST = new LinkedList<>();


    /**
     * 购物车添加信息
     *
     * @param buyCar 购物车集合
     */
    @Override
    public void add(BuyCar buyCar) {
        boolean flag = false;
        for (BuyCar car : CAR_LIST) {
            if (car.getId().equals(buyCar.getId())) {
                flag = true;
                break;
            }
        }
        if (flag) {
            for (BuyCar car : CAR_LIST) {
                if (car.getId().equals(buyCar.getId())) {
                    car.setBuyNum(car.getBuyNum() + buyCar.getBuyNum());
                }
            }
        }
        else {
            CAR_LIST.add(buyCar);
        }
    }

    /**
     * 展示用户信息
     *
     * @param user 用户登录的信息对象
     */
    @Override
    public void showUserInfo(User user) {
        System.out.println("登录名：" + user.getUserName());
        System.out.println("年龄：" + user.getAge());
        System.out.println("昵称：" + user.getOtherName());
    }

    /**
     * 清空购物车
     */
    @Override
    public void clearBuyCar(LinkedList<BuyCar> buyCars) {
        buyCars.clear();
    }
}
